//
//  StatusCell.swift
//  Weibo
//
//  Created by 冯童童 on 16/1/18.
//  Copyright © 2016年 冯童童. All rights reserved.
//

import UIKit
import SnapKit

class StatusCell: UITableViewCell {
    
    var bottomViewTopConstraints : Constraint?
    
    var status : Status? {
        didSet {
            statusOriginalView.status = status
            
            
            self.bottomViewTopConstraints?.uninstall()
            if let re = status?.retweeted_status {
                
                statusCellRetweetedView.retweeted_status = re
                 statusCellRetweetedView.hidden = false
                statusCellBottonView.snp_updateConstraints(closure: { (make) -> Void in
                    self.bottomViewTopConstraints = make.top.equalTo(statusCellRetweetedView.snp_bottom).constraint
                })
                
            } else {
                
                statusCellRetweetedView.hidden = true
                
                statusCellBottonView.snp_updateConstraints(closure: { (make) -> Void in
                    self.bottomViewTopConstraints = make.top.equalTo(statusOriginalView.snp_bottom).constraint
                })

                
            }
        }
    }

    
    override init(style: UITableViewCellStyle, reuseIdentifier: String?) {
        super.init(style: style, reuseIdentifier: reuseIdentifier)
        selectionStyle = .None
        setupUI()
    }

    required init?(coder aDecoder: NSCoder) {
        fatalError("init(coder:) has not been implemented")
    }
    
    private func setupUI() {
        //backgroundColor = UIColor.yellowColor()
        contentView.addSubview(statusOriginalView)
        contentView.addSubview(statusCellRetweetedView)
        contentView.addSubview(statusCellBottonView)
        
        statusOriginalView.snp_makeConstraints { (make) -> Void in
            make.top.left.right.equalTo(contentView)
           // make.height.equalTo(80)
        }
        
        statusCellRetweetedView.snp_makeConstraints { (make) -> Void in
            make.top.equalTo(statusOriginalView.snp_bottom)
            make.left.equalTo(statusOriginalView.snp_left)
            make.right.equalTo(statusOriginalView.snp_right)

        }
        
        statusCellBottonView.snp_makeConstraints { (make) -> Void in
          self.bottomViewTopConstraints = make.top.equalTo(statusCellRetweetedView.snp_bottom).constraint
            make.left.right.equalTo(contentView)
            make.height.equalTo(35)
        }
        
        contentView.snp_makeConstraints { (make) -> Void in
            make.left.top.right.equalTo(self)
            make.bottom.equalTo(statusCellBottonView.snp_bottom)
        }
    
    }
    
    
    
    
    
    override func awakeFromNib() {
        super.awakeFromNib()
        // Initialization code
    }

    override func setSelected(selected: Bool, animated: Bool) {
        super.setSelected(selected, animated: animated)

        // Configure the view for the selected state
    }

    private lazy var statusOriginalView : StatusOriginalView = StatusOriginalView()
    private lazy var statusCellBottonView : StatusCellBottonView = StatusCellBottonView()
    private lazy var statusCellRetweetedView : StatusCellRetweetedView = StatusCellRetweetedView()

}
